<template>
	<view>
		<van-nav-bar title="个人信息" left-text="返回" left-arrow @click-left="onClickLeft" />
		<van-tabs active="a">
			<van-tab title="我的商品" name="a" >
				<view class="box">
					<view v-show="Pitera" style="margin: 100px auto;">
						<van-empty description="暂无商品" />
					</view>
					<view  class="goods" v-for="(item,index) in MyGoods" :key="index" v-show="item.state!=2">
						<view class="">
							<img @click="jump(item)" style="width: 320rpx;height: 320rpx;border-radius:5%;margin-left: 10rpx;" :src="item.commodityImg" alt="">
						</view>
						<view style="overflow: hidden;white-space: nowrap;text-overflow: ellipsis;font-weight: bold;">
							{{item.commodityName}}
						</view>
						<view style="width: 350rpx;">
							<span style="color: red;font-weight: bold;">￥{{item.currentPrice}}</span>
							<span style="text-decoration: line-through;margin-left: 100rpx;color: gray;">￥{{item.originalPrice}}</span>
						</view>
						<view >
							<button @click="unShelve(item.commodityId)" style="height: 30px;line-height:30px;background-color: darkgrey;color:aliceblue">下架商品</button>
						</view>
						
					</view>
				</view>
			</van-tab>
			<van-tab title="我的评价" name="b">
				<view v-show="empty" style="margin: 100px auto;">
					<van-empty description="暂无评价" />
				</view>
				<view style="margin-left: 20rpx;margin-top: 30rpx;" v-for="(item,index) in Evaluate" :key="index">
					<view style="display: flex;align-items: center;">
						<img style="width: 50rpx;height: 50rpx;border-radius:100%;" :src="item.userPhoto" alt="">
						<span style="width: 280rpx; margin-left:20rpx ;color: gray;overflow: hidden;white-space: nowrap;text-overflow: ellipsis;">{{item.userName}}</span>
					</view>
					<view style="margin-left: 50rpx;">
						<view class="">
							{{item.commentsToSeller}}
						</view>
						<view v-show="item.commentImg.length>0">
							<img style="width: 600rpx;height: 600rpx;" :src="item.commentImg" alt="">
						</view>
						<view style="color: gray;">
							{{item.time}}
						</view>
					</view>
				</view>
				
			</van-tab>
		</van-tabs>
	</view>
</template>

<script>
	import request from '../../com/request.js'
	export default {
		data() {
			return {
				MyGoods:[],
				Evaluate:[],
				Pitera:true,
				empty:true
			}
		},
		methods: {
			onClickLeft() {
				uni.redirectTo({
					url: '/pages/MyCenter/MyCenter'
				});
			  },
			unShelve(commodityId){
				request({
					url: 'api/unShelve/get',
					data: {
						commodityId: commodityId
					},
					success: (resp) => {
						this.selectMyGoods()
					}
				})
			},
			selectMyGoods(){
				request({
					url: 'api/selectMyGoods/get',
					data: {
						acc: uni.getStorageSync("userTel")
					},
					success: (resp) => {
						this.MyGoods=resp.data.data
						if(this.MyGoods.length>0){
							this.Pitera=false
						}
						console.log(this.MyGoods,56)
					}
				})
			},
			jump(item){
				uni.setStorageSync('hx220408commodityId',item.commodityId)
				uni.setStorageSync('hx220408userTel',item.userTel)
				uni.redirectTo({
					url: '/pages/goods/goods'
				})
			}
		},
		onLoad(){
			
			this.selectMyGoods()
			request({
				url: 'api/selectEvaluate/get',
				data: {
					acc: uni.getStorageSync("userTel")
				},
				success: (resp) => {
					this.Evaluate=resp.data.data
					if(this.Evaluate.length>0){
						this.empty=false
					}
					console.log(this.Evaluate,78)
				}
			})
		}
	}
</script>

<style>
.goods{
	width: 350rpx;
	margin-left: 22rpx;
	margin-top: 15px;
}
.box{
	display:flex;
	flex-wrap: wrap;
}
</style>
